<?php

declare (strict_types=1);
namespace App\Admin\Controller;

use App\Admin\Model\UserModel;
use App\Admin\Service\UserService;
use App\Event\AppException;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Utils\Context;
use Psr\EventDispatcher\EventDispatcherInterface;
use function _HumbugBoxa5be08ba8ddb\React\Promise\Stream\first;
/**
 * 用户控制器
 * Class UserController
 * @package App\Admin\Controller
 * @AutoController()
 */
class UserController extends AdminBaseController
{
    use \Hyperf\Di\Aop\ProxyTrait;
    use \Hyperf\Di\Aop\PropertyHandlerTrait;
    function __construct()
    {
        if (method_exists(parent::class, '__construct')) {
            parent::__construct(...func_get_args());
        }
        $this->__handlePropertyHandler(__CLASS__);
    }
    /**
     * @Inject()
     * @var UserService
     */
    public $userService;
    /**
     * @Inject()
     * @var UserModel
     */
    public $userModel;
    /**
     * @Inject
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;
    public function register()
    {
        // 调用用户注册服务
        $this->userService->register();
    }
    /**
     * request
     */
    public function add()
    {
        $path = $this->request->getPathInfo();
        $requestUri = $this->request->getRequestUri();
        $uri = $this->request->getUri();
        $method = $this->request->getMethod();
        $url = $this->request->url();
        $fullUrl = $this->request->fullUrl();
        $all = $this->request->all();
        $cookies = $this->request->getCookieParams();
        $headers = $this->request->getHeaders();
        var_dump([$path, $requestUri, $uri, $method, $url, $fullUrl, $all, $cookies, $headers]);
        //        array(9) {
        //        [0]=>
        //  string(9) "/user/add"
        //        [1]=>
        //  string(9) "/user/add"
        //        [2]=>
        //  object(Hyperf\HttpMessage\Uri\Uri)#87006 (7) {
        //  ["scheme":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(4) "http"
        //        ["userInfo":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(0) ""
        //        ["host":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(10) "web.hf.com"
        //        ["port":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    NULL
        //    ["path":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(9) "/user/add"
        //        ["query":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(23) "id=1&token=123&isopen=1"
        //        ["fragment":"Hyperf\HttpMessage\Uri\Uri":private]=>
        //    string(0) ""
        //  }
        //  [3]=>
        //  string(3) "GET"
        //    [4]=>
        //  string(26) "http://web.hf.com/user/add"
        //    [5]=>
        //  string(50) "http://web.hf.com/user/add?id=1&isopen=1&token=123"
        //    [6]=>
        //  array(3) {
        //        ["id"]=>
        //    string(1) "1"
        //        ["token"]=>
        //    string(3) "123"
        //        ["isopen"]=>
        //    string(1) "1"
        //  }
        //  [7]=>
        //  array(0) {
        //    }
        //  [8]=>
        //  array(10) {
        //        ["host"]=>
        //    array(1) {
        //            [0]=>
        //      string(13) "web.hf.com:80"
        //    }
        //    ["x-real-ip"]=>
        //    array(1) {
        //            [0]=>
        //      string(12) "192.168.33.1"
        //    }
        //    ["x-real-port"]=>
        //    array(1) {
        //            [0]=>
        //      string(5) "60563"
        //    }
        //    ["x-forwarded-for"]=>
        //    array(1) {
        //            [0]=>
        //      string(12) "192.168.33.1"
        //    }
        //    ["connection"]=>
        //    array(1) {
        //            [0]=>
        //      string(5) "close"
        //    }
        //    ["upgrade-insecure-requests"]=>
        //    array(1) {
        //            [0]=>
        //      string(1) "1"
        //    }
        //    ["user-agent"]=>
        //    array(1) {
        //            [0]=>
        //      string(115) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"
        //    }
        //    ["accept"]=>
        //    array(1) {
        //            [0]=>
        //      string(135) "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
        //    }
        //    ["accept-encoding"]=>
        //    array(1) {
        //            [0]=>
        //      string(13) "gzip, deflate"
        //    }
        //    ["accept-language"]=>
        //    array(1) {
        //            [0]=>
        //      string(23) "zh-CN,zh;q=0.9,en;q=0.8"
        //    }
        //  }
        //}
    }
    /**
     * 异常测试
     */
    public function exception()
    {
        try {
            array_column();
        } catch (\Throwable $throwable) {
            $this->eventDispatcher->dispatch(new AppException($throwable));
        }
    }
    /**
     * 异常测试
     */
    public function info()
    {
        try {
            array_combine();
        } catch (\Throwable $throwable) {
            $this->eventDispatcher->dispatch(new AppException($throwable));
        }
    }
    public function orm()
    {
        $first = Db::table('yonghu')->first();
        var_dump($first);
    }
}